import java.lang.reflect.Type;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.google.gson.Gson;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;

public class DateAdapter implements JsonDeserializer<Date> {
	private final DateFormat df = new SimpleDateFormat("yyyy-MM-dd");

	@Override
	public Date deserialize(JsonElement arg0, Type arg1,
			JsonDeserializationContext arg2) throws JsonParseException {
		Gson g = new Gson();
		DateTest dt = g.fromJson(arg0, DateTest.class);
		Date d = new Date(dt.time);
		System.out.println(arg0);
		System.out.println(df.format(d));
		return d;
		// try {
		// return df.parse(arg0.getAsString());
		// } catch (ParseException e) {
		// e.printStackTrace();
		// }
		// return null;
	}
}
